<?php
namespace Home\Controller;
use Lib\Api\AgentApi;
use Lib\Api\AgentBelongApi;
use Lib\Api\CustomerApi;
use Lib\Api\OrderApi;
use Lib\Api\OrganizationApi;
use Lib\Api\OrganizationBelongApi;
use Lib\Api\RebateRatio;
use Lib\Api\RechargeWithdrawalsApi;
use Lib\Api\SysApi;
use Lib\Api\TradeDetailApi;
use Lib\Api\UserApi;
use Lib\Api\UserBelongApi;
use Lib\Utils\Utils;
use Think\Controller;

class UserController extends Controller {

    public function index() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$url = isLogin();
        if ($url != false) {
            header("Location:".$url);
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }

        $user_id = 0;
        if (!empty(session('user_id'))) {
            // exit("登录失效，请重新用公会号登录");
            $user_id = session('user_id');
        }

        $modelName = 'User';
        $modelObj = M($modelName);
        $data = $modelObj->where(array('id' => $user_id))->find();
        $data['nick_name'] = Utils::userTextDecode($data['nick_name'] );
        $this->assign('user', $data);

        $map["a.user_id"] = $user_id;
        $map['a.state'] = array('neq', 0);
        $total_gain_money = $modelObj->table('fs_order a')
            ->where($map)
            ->sum('a.gain_price');
        $this->assign('total_gain_money', $total_gain_money);


        $position_map['a.state'] = array('eq', 0);
        $position_map['a.user_id'] = array('eq', $user_id);
        $position_num = $modelObj->table('fs_order a')
            ->where($position_map)
            ->sum('a.mun');
        $this->assign('position_num', $position_num);

        $position_sum = $modelObj->table('fs_order a')
            ->where($position_map)
            ->sum('a.real_price*a.mun');
        $this->assign('position_sum', $position_sum);

        /*$data = $modelObj->where(array('pid' => session('user_id')))->count();
        $this->assign('team_num', $data);*/

        $modelObj = M("Sys");
        $data = $modelObj->field("lowest_money, highest_money, max_extract_count")->where(array('id' => 1))->find();
        $this->assign('sys', $data);

        $this->display();

    }

    public function sub_login() {
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }

        $sms_code = '123456';
        if (!empty($_POST['sms_code'])) {
            $sms_code = $_POST['sms_code'];
        }

        if (empty($_POST['mobile_phone']))  {
            $data['code'] = -1;
            $data['msg'] = '手机号码不能为空';
            $this->ajaxReturn($data);
            exit;
        } else if (!preg_match("/^\\s*1\\d{10}\\s*$/", $_POST['mobile_phone'])) {
            $data['code'] = -1;
            $data['msg'] = '手机号码不正确';
            $this->ajaxReturn($data);
            exit;
        }
        $mobilePhone = stripslashes(trim($_POST['mobile_phone']));
        $map['mobile_phone'] = $mobilePhone;
		$map['state'] = 0;
        // $count = UserApi::getTotal($map);
        $user = UserApi::getInfo($map, "id, password");
        if (!empty($user)) {
			session("user_id", $user["id"]);
            session("mobile_phone", $mobilePhone);
            if (empty($user['password'])) {
                session("set_password", 0);
            } else {
                session("set_password", 2);
            }
            $data['code'] = 1;
        } else {
            $data['code'] = -1;
            $data['msg'] = '手机号码不存在';
        }
        $this->ajaxReturn($data);
    }

    public function check_password() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$arr['url'] = isLogin();
        if ($arr['url'] != false) {
            $this->ajaxReturn($arr);
            exit;
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }

        if (empty($_POST['password']))  {
            $data['code'] = -1;
            $data['msg'] = '交易密码不能为空';
            $this->ajaxReturn($data);
            exit;
        }
        $md5Password = md5($_POST['password']);
        $user = UserApi::getInfo(array("id"=>session("user_id")));
        if (!empty($user)) {
            if (empty($user["password"])) {
                // 设置一个新密码
                $user["password"] = $md5Password;
                UserApi::save($user);
                session("set_password", 1);
                $data['code'] = 1;
            } else {
                // 判断密码是否正确
                if ($user["password"] == $md5Password) {
                    session("set_password", 1);
                    $data['code'] = 1;
                } else {
                    $data['code'] = -1;
                    $data['msg'] = '已有交易密码，交易密码错误';
                }
            }
        } else {
            $data['code'] = -1;
            $data['msg'] = '没有找到用户';
        }
        $this->ajaxReturn($data);
    }

    public function forget_password() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$url = isLogin();
        if ($url != false) {
            header("Location:".$url);
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }
        $this->display();
    }

    public function sub_forget_password() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$arr['url'] = isLogin();
        if ($arr['url'] != false) {
            $this->ajaxReturn($arr);
            exit;
        }
        $userModel = M('User');
        $user = $userModel->create($_POST);

        $sms_code = '';
        if (!empty($_POST['sms_code'])) {
            $sms_code = $_POST['sms_code'];
        }
        if (empty($user['mobile_phone'])) {
            $data['success'] = 0;
            $data['msg'] = '手机号码不能为空';
            $this->ajaxReturn($data);
            exit;
        } else if (!preg_match("/^[0-9][0-9]{1}\\d{9}$/", $user['mobile_phone'])) {
            $data['success'] = 0;
            $data['msg'] = '手机号码不正确';
            $this->ajaxReturn($data);
            exit;
        }
        $mobilePhone = stripslashes(trim($user['mobile_phone']));
        if (empty(cookie($mobilePhone))) {
            $data['success'] = 0;
            $data['msg'] = '手机验证码已失效，请重新发送';
            $this->ajaxReturn($data);
            exit;
        } else if (cookie($mobilePhone) != $sms_code) {
            $data['success'] = 0;
            $data['msg'] = '手机验证码错误';
            $this->ajaxReturn($data);
            exit;
        }
        if (empty($user['password'])) {
            $data['success'] = 0;
            $data['msg'] = '新交易密码不能为空';
            $this->ajaxReturn($data);
            exit;
        }

        $userObj = $userModel->where("mobile_phone=".$mobilePhone)->find();
        if (!empty($userObj)) {
            $userObj['password'] = md5($user['password']);
            $userModel->save($userObj);
            $data['success'] = 1;
            $data['msg'] = '修改密码成功';
            $this->ajaxReturn($data);
        } else {
            $data['success'] = 0;
            $data['msg'] = '修改失败，手机号码不存在';
            $this->ajaxReturn($data);
        }
    }

    public function sendSMS() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
        $type = "r";
        if (empty($_POST['mobile_phone']) || $_POST['mobile_phone'] == "")  {
            $data['success'] = 1;
            $data['msg'] = '手机号码不能为空';
            $this->ajaxReturn($data);
            exit;
        } else if ($_POST['mobile_phone'] == 1) {
            if (!empty(session("user_id"))) {
                $user = UserApi::getInfo(array("id"=>session("user_id")));
                $mobilePhone = $user['mobile_phone'];
            } else {
                $data['success'] = 1;
                $data['msg'] = '登录已失效，请重新登录';
                $this->ajaxReturn($data);
                exit;
            }
        } else if (!preg_match("/^[0-9][0-9]{1}\\d{9}$/", $_POST['mobile_phone'])) {
            $data['success'] = 1;
            $data['msg'] = '手机号码不正确';
            $this->ajaxReturn($data);
            exit;
        } else {
            $mobilePhone = stripslashes(trim($_POST['mobile_phone']));
        }
        if (!empty($_POST['type']) && $_POST['type'] != "") {
            $type = $_POST['type'];
        }

        // $organization_code = '000008888';
        if ($type == "l") {
            // $left = "left join fs_user_belong b on b.user_id = a.id left join fs_organization c on c.id = b.organization_id";
            $where['_string'] = "a.mobile_phone = '".$mobilePhone."'";
            $user_num = UserApi::getTotalByCondition($where);
        } else {
            if (!empty(session("organization_code"))) {
                $organization_code = session("organization_code");
            } else {
                $data['success'] = 1;
                $data['msg'] = '发送失败';
                $this->ajaxReturn($data);
                exit;
            }

            $left = "left join fs_user_belong b on b.user_id = a.id left join fs_organization c on c.id = b.organization_id";
            $where['_string'] = "a.mobile_phone = '".$mobilePhone."' and concat(c.p_code,c.level,c.code)='".$organization_code."'";
            $user_num = UserApi::getTotalByCondition($where, $left);
        }

        if ($type == "r") {
            if ($user_num > 0) {
                /*$data['success'] = 1;
                $data['msg'] = '该手机号码已被注册了';
                $this->ajaxReturn($data);
                exit;*/
            }
        } else if ($type == "f" || $type == "l")  {
            if ($user_num == 0) {
                $data['success'] = 1;
                $data['msg'] = '手机号码不存在';
                $this->ajaxReturn($data);
                exit;
            }
        }

        $sys = SysApi::getInfo(array("id"=>1), "sms_account, sms_pwd, reg_sms_content");

        $sms_reg_code = rand_number(1, 999999);

        // session(array('id'=>$mobilePhone, 'name'=>$sms_reg_code,'expire'=>3600));
        // session($mobilePhone, $sms_reg_code);
        // session('sms_reg_code', $sms_reg_code);
        cookie($mobilePhone, $sms_reg_code, 5 * 60);

        $reg_sms_content = str_replace("{code}",$sms_reg_code,$sys['reg_sms_content']);
        $statusStr = array(
            "0" => "短信发送成功",
            "-1" => "参数不全",
            "-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
            "30" => "密码错误",
            "40" => "账号不存在",
            "41" => "短信余额不足，请联系管理员",
            "42" => "帐户已过期",
            "43" => "IP地址限制",
            "50" => "内容含有敏感词"
        );

        $smsapi = "http://api.smsbao.com/";
        $sms_account = $sys['sms_account']; //短信平台帐号
        $sms_pwd = md5($sys['sms_pwd']); //短信平台密码
        $sendurl = $smsapi."sms?u=".$sms_account."&p=".$sms_pwd."&m=".$mobilePhone."&c=".urlencode($reg_sms_content);
        $result = file_get_contents($sendurl);

        $data["success"]=$result;
        $data["msg"]=$statusStr[$result];
        $this->ajaxReturn($data);
    }

    public function changesMobile() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }

        if (empty($_POST['mobile_phone']) || $_POST['mobile_phone'] == "")  {
            $data['code'] = 0;
            $data['msg'] = '手机号码不能为空';
            $this->ajaxReturn($data);
            exit;
        } else if (!preg_match("/^[0-9][0-9]{1}\\d{9}$/", $_POST['mobile_phone'])) {
            $data['code'] = 0;
            $data['msg'] = '手机号码不正确';
            $this->ajaxReturn($data);
            exit;
        } else {
            $mobilePhone = stripslashes(trim($_POST['mobile_phone']));
        }
        $sms_code = '';
        if (!empty($_POST['sms_code'])) {
            $sms_code = $_POST['sms_code'];
        }
        if (empty(cookie($mobilePhone))) {
            $data['code'] = 0;
            $data['msg'] = '手机验证码已失效，请重新发送';
            $this->ajaxReturn($data);
            exit;
        } else if (cookie($mobilePhone) != $sms_code) {
            $data['code'] = 0;
            $data['msg'] = '手机验证码错误';
            $this->ajaxReturn($data);
            exit;
        } else {
			cookie($mobilePhone, null);
		}
		

        /*$userModel = M("User");
        $userObj = $userModel->where("mobile_phone=".$mobilePhone)->count("id");*/
		
		/*$left = "left join fs_user_belong b on b.user_id = a.id left join fs_organization c on c.id = b.organization_id";
            $where['_string'] = "a.mobile_phone = '".$mobilePhone."' and concat(c.p_code,c.level,c.code)='".$organization_code."'";
            $user_num = UserApi::getTotalByCondition($where, $left);*/

        $organization_code = session("organization_code");
		$session_user_id = session('user_id');
        $left = "left join fs_user_belong b on b.user_id = a.id left join fs_organization c on c.id = b.organization_id";
        $where['_string'] = "a.mobile_phone = '".$mobilePhone."' and concat(c.p_code,c.level,c.code)='".$organization_code."'";

		$user = UserApi::getInfoByCondition($where, $left, "a.*");

        if (empty($user)) {
            $modelObj = M("User");
            $map['id'] = $session_user_id;
            $data = $modelObj->where($map)->find();
            $data['mobile_phone'] = $mobilePhone;
            $modelObj->save($data);

            $ajaxdata['code'] = 1;
            $ajaxdata['msg'] = '手机绑定成功';
            $this->ajaxReturn($ajaxdata);
        } else {
            $del_user = UserApi::getInfo(array("id"=>$session_user_id), "id, wx_id");
			
			$path = "C:/HwsApacheMaster/wwwroot/400tcc_xzRyaq/log/wx/";
			if (!is_dir($path)){
				mkdir($path,0777);  // 创建文件夹test,并给777的权限（所有权限）
			}
			$file = $path.'changesMobile.txt';
			$log = "老用户帐户找回，邦定手机号码：".$mobilePhone."，要删除用户ID：".$session_user_id."要修改用户ID：".$user['id'];
			$log .= "\r\n----------------------------------\r\n";
			file_put_contents($file,$log,FILE_APPEND);
			
            $user['wx_id'] = $del_user['wx_id'];
            UserApi::save($user);
			
            UserApi::delete(array("id"=>$session_user_id));
            UserBelongApi::delete("UserBelong", array("user_id"=>$session_user_id));
			
			session("user_id", $user['id']);
            session("set_password", 2);

            $ajaxdata['code'] = 1;
            $ajaxdata['msg'] = '手机绑定成功';
            $this->ajaxReturn($ajaxdata);
			/*
			$data['code'] = 0;
            $data['msg'] = '手机绑定，手机已被注册';
            $this->ajaxReturn($data);
			*/
        }
    }

    public function changesPass() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$arr['url'] = isLogin();
        if ($arr['url'] != false) {
            $this->ajaxReturn($arr);
            exit;
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }

        if (!empty($_POST['old_password'])) {
            $old_password = md5($_POST['old_password']);
        } else {
            $ajaxdata['code'] = 0;
            $ajaxdata['msg'] = '当前交易密码不能为空';
            $this->ajaxReturn($ajaxdata);
            exit;
        }
        if (!empty($_POST['password'])) {
            $password = md5($_POST['password']);
        } else {
            $ajaxdata['code'] = 0;
            $ajaxdata['msg'] = '新交易密码不能为空';
            $this->ajaxReturn($ajaxdata);
            exit;
        }

        $modelObj = M("User");
        $user_id = session('user_id');
        $map['id'] = $user_id;
        $data = $modelObj->where($map)->find();
        if ($data['password'] != $old_password) {
            $ajaxdata['code'] = 0;
            $ajaxdata['msg'] = '当前交易密码不正确';
            $this->ajaxReturn($ajaxdata);
            exit;
        }
        $data['password'] = $password;
        $modelObj->save($data);

        $ajaxdata['code'] = 1;
        $ajaxdata['msg'] = '交易密码已修改';
        $this->ajaxReturn($ajaxdata);
    }

    public function changesInfo() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$arr['url'] = isLogin();
        if ($arr['url'] != false) {
            $this->ajaxReturn($arr);
            exit;
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }
        $user_id = session('user_id');
        $modelObj = M("User");
        $data = $modelObj->create($_POST);
        $data["id"] = $user_id;
        $modelObj->save($data);

        $ajaxdata['code'] = 1;
        $ajaxdata['msg'] = '用户信息已修改';
        $this->ajaxReturn($ajaxdata);
    }

    public function mychongti() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$url = isLogin();
        if ($url != false) {
            header("Location:".$url);
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }
        $this->display();
    }

    public function bills() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$url = isLogin();
        if ($url != false) {
            header("Location:".$url);
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }
       $this->display();
    }

    public function loadMyBills() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$arr['url'] = isLogin();
        if ($arr['url'] != false) {
            $this->ajaxReturn($arr);
            exit;
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }

        $pageNo = $_POST['page'];
        $pageSize = $_POST['pageSize'];
        $date_time = $_POST['date_time'];
        $user_id = session("user_id");

        $map['user_id'] = array('eq', $user_id);
        if ($date_time == 1) {
            $beginDate = date('Y-m-01', strtotime(date("Y-m-d")));
            $endDate = date('Y-m-d', strtotime("$beginDate +1 month -1 day"));
            $map['DATE_FORMAT(datetime, "%Y-%m-%d")'] = array(array('egt', $beginDate), array('elt',$endDate));
        } else if ($date_time == 2) {
            $temp_date = date('Y-m-01', strtotime(date("Y-m-d")));
            $endDate = date('Y-m-d', strtotime("$temp_date +1 month -1 day"));
            $beginDate = date('Y-m-d', strtotime("$endDate -3 month +1 day"));
            $map['DATE_FORMAT(datetime, "%Y-%m-%d")'] = array(array('egt', $beginDate), array('elt',$endDate));
        }

        $list = RechargeWithdrawalsApi::getList($map, "", "*", $pageNo, $pageSize, "datetime desc");
        $totals = RechargeWithdrawalsApi::getTotal($map);

        if (count($list) > 0) {
            for ($i=0; $i<count($list);$i++) {
                switch ($list[$i]['type'])
                {
                    case 1:
                        $list[$i]['type_name'] = '充值';
                        if ($list[$i]['state'] == 1) {
                            $list[$i]['type_css'] = "chong";
                        }
                        break;
                    case 2:
                        $list[$i]['type_name'] = '提现';
                        if ($list[$i]['audit_state'] == 1) {
                            $list[$i]['type_css'] = "ti2";
                        } else if ($list[$i]['audit_state'] == 2) {
                            $list[$i]['type_css'] = "57ad2e";
                        }
                        break;
                    default:
                }
            }

            $ajaxdata['success'] = 1;
            $ajaxdata['data'] = $list;
            $ajaxdata['count'] = $totals;
            $this->ajaxReturn($ajaxdata);
        } else {
            $ajaxdata['success'] = 1;
            $ajaxdata['msg'] = '当前没有任何记录';
            $ajaxdata['count'] = 0;
            $this->ajaxReturn($ajaxdata);
        }
    }

    public function mytrade() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$url = isLogin();
        if ($url != false) {
            header("Location:".$url);
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }
        $this->display();
    }

    // 获取用户余额
    public function user_money() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$arr['url'] = isLogin();
        if ($arr['url'] != false) {
            $this->ajaxReturn($arr);
            exit;
        }
		
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }

        $user_id = session("user_id");
        $modelName = 'User';
        $modelObj = M($modelName);
        $map['id'] = $user_id;
        $data = $modelObj->where($map)->field('balance')->find();
        $ajaxdata['user'] = $data;
        $this->ajaxReturn($ajaxdata);
    }

    public function withdrawals() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$url = isLogin();
        if ($url != false) {
            header("Location:".$url);
        }
		
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }

        if (empty(session('user_id'))) {
            session("showLogin", 1);
            $rel_url = "../index";
            redirect($rel_url);
            // $this->display($rel_url);
            exit;
        }

        $modelObj = M("user");
        $data = $modelObj->field("REPLACE(mobile_phone, SUBSTR(mobile_phone,4,4), '****') as mobile_phone, balance, photo_url, nick_name")->where(array('id' => session('user_id')))->find();
        $this->assign('user', $data);

        $modelObj = M("UserBank");
        $userBank_list = $modelObj->where(array('user_id'=>session('user_id')))->select();
        $userBank = array();
        if (!empty($userBank_list)) {
            $userBank = $userBank_list[0];
        }
        $this->assign('userBank', $userBank);
		
		$this->assign('source', 1);

        $modelObj = M("Sys");
        $data = $modelObj->field("lowest_money, highest_money, max_extract_count")->where(array('id' => 1))->find();
        $this->assign('sys', $data);

        $this->display();
    }

    // 用户提现
    public function userDraw() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$arr['url'] = isLogin();
        if ($arr['url'] != false) {
            $this->ajaxReturn($arr);
            exit;
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }

        /*$userModel = M("User");
        $user_id = session('user_id');
        $user = $userModel->field('balance, password, mobile_phone')->where(array('id' => $user_id))->find();*/

        $source = 1;
        if (!empty($_POST['source'])) {
            $source = $_POST['source'];
        }
        $user_id = session('user_id');
        if ($source == 1) {
            $userModel = M("User");
            $user = $userModel->field('balance, password, mobile_phone')->where(array('id' => $user_id))->find();;
        } else {
            $user = AgentApi::getInfo(array("b.id"=>$user_id),"left join fs_user b on b.agent_id = a.id","a.id as agent_id, a.balance, b.password, b.mobile_phone");
        }

        $sysModel = M("Sys");
        $sys = $sysModel->field('lowest_money, highest_money, max_extract_count')->where(array('id' => 1))->find();

        if (empty($_POST['money'])) {
            $rel['code'] = 0;
            $rel['msg'] = '请填写提取金额';
            $this->ajaxReturn($rel);
            exit;
        } else if (is_numeric($_POST['money']) == false) {
            $rel['code'] = 0;
            $rel['msg'] = '输入的提取金额不正确';
            $this->ajaxReturn($rel);
            exit;
        } else if ($_POST['money'] < $sys['lowest_money']) {
            $rel['code'] = 0;
            $rel['msg'] = '最低提现金额为'.$sys['lowest_money'].'元';
            $this->ajaxReturn($rel);
            exit;
        } else if ($_POST['money'] > $user['balance']) {
            $rel['code'] = 0;
            $rel['msg'] = '您目前的最大提取额度为'.$user['balance'].'元';
            $this->ajaxReturn($rel);
            exit;
        } else if ($_POST['money'] > $sys['highest_money']) {
            $rel['code'] = 0;
            $rel['msg'] = '最大提现金额为'.$sys['highest_money'].'元';
            $this->ajaxReturn($rel);
            exit;
        }
        $money = $_POST['money'];

        if (empty($_POST['bank_name'])) {
            $rel['code'] = 0;
            $rel['msg'] = '请选择开卡银行';
            $this->ajaxReturn($rel);
            exit;
        }
        $bank_name = $_POST['bank_name'];

        if (empty($_POST['bank_province'])) {
            $rel['code'] = 0;
            $rel['msg'] = '请选择开卡省份';
            $this->ajaxReturn($rel);
            exit;
        }
        $bank_province = $_POST['bank_province'];

        if (empty($_POST['bank_city'])) {
            $rel['code'] = 0;
            $rel['msg'] = '请选择开卡城市';
            $this->ajaxReturn($rel);
            exit;
        }
        $bank_city = $_POST['bank_city'];

        $bank_address = $bank_province.$bank_city;

        if (empty($_POST['bank_no'])) {
            $rel['code'] = 0;
            $rel['msg'] = '请输入银行卡卡号';
            $this->ajaxReturn($rel);
            exit;
        }
        $bank_no = $_POST['bank_no'];

        if (empty($_POST['cardholder'])) {
            $rel['code'] = 0;
            $rel['msg'] = '请输入持卡人姓名';
            $this->ajaxReturn($rel);
            exit;
        }
        $cardholder = $_POST['cardholder'];

        if (empty($_POST['identity'])) {
            $rel['code'] = 0;
            $rel['msg'] = '请输入持卡人身份证';
            $this->ajaxReturn($rel);
            exit;
        }
        $identity = $_POST['identity'];

        $sms_code = '';
        if (!empty($_POST['smsCode'])) {
            $sms_code = $_POST['smsCode'];
        }
        if (empty(cookie($user['mobile_phone']))) {
            $data['success'] = 0;
            $data['msg'] = '手机验证码已失效，请重新发送';
            $this->ajaxReturn($data);
            exit;
        } else if (cookie($user['mobile_phone']) != $sms_code) {
            $data['success'] = 0;
            $data['msg'] = '手机验证码错误';
            $this->ajaxReturn($data);
            exit;
        }

        if (empty($_POST['password'])) {
            $rel['code'] = 0;
            $rel['msg'] = '请填写交易密码';
            $this->ajaxReturn($rel);
            exit;
        }
        $password = $_POST['password'];

        if (md5($password) != $user['password']) {
            $rel['code'] = 0;
            $rel['msg'] = '交易密码错误';
            $this->ajaxReturn($rel);
            exit;
        }

        $out_trade_no = date('YmdHi').$user_id.rand_number(1, 999);

        $modelObj = M("RechargeWithdrawals");
        $userDraw["user_id"] = $user_id;
        $userDraw["out_trade_no"] = $out_trade_no;
        $userDraw["source"] = $source;
        $userDraw["money"] = $money;
        $userDraw["type"] = 2;
        $userDraw["bank_name"] = $bank_name;
        $userDraw["bank_no"] = $bank_no;
        $userDraw["bank_address"] = $bank_address;
        $userDraw["cardholder"] = $cardholder;
        $userDraw["identity"] = $identity;
        $userDraw["state"] = 1;
        $userDraw["audit_state"] = 2;
        $userDraw["datetime"] = date('Y-m-d H:i:s');
        if ($source == 1) {
            $userDraw["remark"] = "余额提现";
        } else {
            $userDraw["remark"] = "经纪人收益提现";
        }
        $modelObj->add($userDraw);

        if ($source == 1) {
            $modelObj = M("User");
            $user_data['id'] = $user_id;
            $user_data['balance'] = array('exp','balance-'.$money);
            $user_data['freeze_balance'] = array('exp','freeze_balance+'.$money);
            $modelObj->save($user_data);
            $user_data = $modelObj->where("id=$user_id")->field('balance')->find();

            $modelObj = M("TradeDetail");
            $params = array("user_id"=>$user_id, "deal_user_id"=>0, "out_trade_no"=>"$out_trade_no", "type"=>6,
                "money"=>$money, "fee_money"=>0, "other_money"=>0,"balance"=>$user_data['balance'], "source"=>7,
                "state"=>1, "datetime"=>date('Y-m-d H:i:s'));
            $modelObj->add($params);
        } else {
            $agent_data['balance'] = array('exp','balance-'.$money);
            $agent_data['freeze_money'] = array('exp','freeze_money+'.$money);
            AgentApi::saveByCondition(array("id"=>$user['agent_id']), $agent_data);
            $agent_data = AgentApi::getInfo(array("a.id"=>$user['agent_id']), "", "a.balance");

            $modelObj = M("TradeDetail");
            $params = array("user_id"=>$user_id, "deal_user_id"=>0, "out_trade_no"=>"$out_trade_no", "type"=>6,
                "money"=>$money, "fee_money"=>0, "other_money"=>0,"balance"=>$agent_data['balance'], "source"=>8,
                "state"=>1, "datetime"=>date('Y-m-d H:i:s'));
            $modelObj->add($params);
        }

        $modelObj = M("UserBank");
        $userBank_list = $modelObj->where("user_id=$user_id")->select();
        if (empty($userBank_list)) {
            $userBank["user_id"] = $user_id;
            $userBank["bank_name"] = $bank_name;
            $userBank["bank_no"] = $bank_no;
            $userBank["bank_province"] = $bank_province;
            $userBank["bank_city"] = $bank_city;
            $userBank["cardholder"] = $cardholder;
            $userBank["identity"] = $identity;
            $modelObj->add($userBank);
        } else {
            $userBank_list[0]["bank_name"] = $bank_name;
            $userBank_list[0]["bank_no"] = $bank_no;
            $userBank_list[0]["bank_province"] = $bank_province;
            $userBank_list[0]["bank_city"] = $bank_city;
            $userBank_list[0]["cardholder"] = $cardholder;
            $userBank_list[0]["identity"] = $identity;
            $modelObj->save($userBank_list[0]);
        }

        cookie($user['mobile_phone'], null);

        $rel['code'] = 1;
        $rel['msg'] = '提现申请已提交，通过审核后，提现资金将在10分钟内到账。<br><font color="red">提现审核时间为工作日09:00-18:00</font>';
        $this->ajaxReturn($rel);
    }

    public function logout() {
        $user_id = 0;
        if (!empty(session("user_id"))) {
            $user_id = session("user_id");
            session('user_id', null);
        }
        $data['user_id'] = $user_id;
        $data['code'] = 0;
        // $this->ajaxReturn($data);

        $rel_url = "../index";
        redirect($rel_url);
    }

    // 获取代金劵
    public function getcoupon() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
        $game_type = $_POST['game_type'];
        $time_type = $_POST['time_type'];
        $buy_money = $_POST['buy_money'];
        $user_id = session('user_id');

        $model = M();
        $field = "a.voucher_range,a.money,b.name,b.use_money,b.type";
        $map['a.user_id'] = $user_id;
        $map['a.state'] = 2;
        $map['DATE_FORMAT(a.start_date, "%Y-%m-%d")'] = array('elt', date('Y-m-d'));
        $map['DATE_FORMAT(a.end_date, "%Y-%m-%d")'] = array('egt', date('Y-m-d'));
        $list = $model->table('fs_voucher a')
            ->join('left join fs_voucher_type b on b.id = a.type')
            //->field('r.name, sm.name, m.id')
            ->field($field)
            ->where($map)
            ->select();

        if (count($list) > 0) {
            $arr = array();
            $data['status'] = 'ok';
            for ($i=0;$i<count($list);$i++) {
                $is_add = true;
                if ($list[$i]['voucher_range'] == 0) {
                    for ($j=0; $j<count($arr); $j++) {
                        if ($arr[$j]['money'] == $list[$i]['money'] && $arr[$j]['type'] == $list[$i]['type']) {
                            $arr[$j]["totals"] = $arr[$j]["totals"]+1;
                            $is_add = false;
                        }
                    }
                } else {
                    $voucher_range = explode(",",$list[$i]['voucher_range']);
                    for ($j=0;$j<count($voucher_range);$j++) {
                        if ($voucher_range[$j] == $game_type) {
                            for ($z=0; $z<count($arr); $z++) {
                                if ($arr[$z]['money'] == $list[$i]['money'] && $arr[$z]['type'] == $list[$i]['type']) {
                                    $arr[$z]["totals"] = $arr[$z]["totals"]+1;
                                    $is_add = false;
                                }
                            }
                        }
                    }
                }

                if ($is_add == true) {
                    $voucher['name'] = $list[$i]['name'];
                    $voucher['money'] = $list[$i]['money'];
                    $voucher['type'] = $list[$i]['type'];
                    $voucher['use_money'] = $list[$i]['use_money'];
                    $voucher['totals'] = 1;
                    $voucher['can_user_num'] = 1;
                    $voucher['message'] = '';
                    /*if ($list[$i]['type'] == 2) {
                        if ($buy_money < $list[$i]['use_money']) {
                            $voucher['can_user_num'] = 0;
                            $voucher['message'] = '投资金额需要满足'.sprintf("%.2f", $list[$i]['use_money']).'元才能使用';
                        } else {
                            $voucher['can_user_num'] = 1;
                            $voucher['message'] = '';
                        }
                    } else {
                        $voucher['can_user_num'] = 1;
                        $voucher['message'] = '';
                    }*/
                    array_push($arr, $voucher);
                }
            }
            $data['list'] = $arr;
        } else {
            $data['status'] = 'no';
        }
        // $data['status'] = $list;
        // $data['list'] = array(array('name'=>"必盈劵",'money'=>10, 'type'=>2, 'message'=>'', 'totals'=>10, 'can_user_num'=>1));
        $this->ajaxReturn($data);
    }

    // 获取用户信息
    public function getinfo() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }

        $fields = $_POST['field'];
        if (!empty(session('user_id'))) {
            $modelName = 'User';
            $modelObj = M($modelName);
            $data = $modelObj->field($fields)->where(array('id' => session('user_id')))->find();

            $field = explode(",",$fields);
            for ($i=0; $i<count($field); $i++) {
                $rel[$field[$i]] = $data[$field[$i]];
            }
            $rel['status'] = 'ok';
        } else {
            $rel['status'] = 'no';
        }
        $this->ajaxReturn($rel);
    }

    public function setting() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$url = isLogin();
        if ($url != false) {
            header("Location:".$url);
        }
        if (empty(session('user_id'))) {
            session("showLogin", 1);
            $rel_url = "../index";
            redirect($rel_url);
            // $this->display($rel_url);
            exit;
        }
        $modelObj = M("user");
        $data = $modelObj->field("REPLACE(mobile_phone, SUBSTR(mobile_phone,4,4), '****') as mobile_phone")->where(array('id' => session('user_id')))->find();
        $this->assign('mobile_phone', $data['mobile_phone']);
        $this->display();
    }

    public function couponlist() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
        $url = isLogin();
        if ($url != false) {
            header("Location:".$url);
        }

        $this->display();
    }

    public function getcouponlist() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$arr['url'] = isLogin();
        if ($arr['url'] != false) {
            $this->ajaxReturn($arr);
            exit;
        }
        $pageNo = $_POST['page'];
        $pageSize = $_POST['pageSize'];

        $state= $_POST['state'];
        $user_id = session('user_id');
        $model = M();
        $field = "a.voucher_range,a.money,a.start_date,a.end_date,b.name,b.use_money,b.type,b.remark, GROUP_CONCAT(distinct c.game_name) as pname, count(a.id) totals, count(distinct c.id) ptotals";
        $map['a.user_id'] = $user_id;
        if ($state == 0) {
            $map['a.state'] = 2;
            $map['DATE_FORMAT(a.end_date, "%Y-%m-%d")'] = array('egt', date('Y-m-d'));
        } else if ($state == 1) {
            $map['a.state'] = 1;
        } else if ($state == 2) {
            $map['DATE_FORMAT(a.end_date, "%Y-%m-%d")'] = array('elt', date('Y-m-d'));
        }

        $list = $model->table('fs_voucher a')
            ->join('left join fs_voucher_type b on b.id = a.type')
            ->join('left join fs_game_type c on FIND_IN_SET(c.id , a.voucher_range)')
            ->field($field)
            ->where($map)
            ->group('a.money,a.start_date,a.end_date,a.type,a.voucher_range')
            ->order('end_date,datetime desc')
            ->page($pageNo, $pageSize)
            ->select();

        $totals = $model->table('fs_voucher a')
            ->join('left join fs_voucher_type b on b.id = a.type')
            ->join('left join fs_game_type c on FIND_IN_SET(c.id , a.voucher_range)')
            ->where($map)
            ->group('a.money,a.start_date,a.end_date,a.type,a.voucher_range')
            ->count('a.id');

        if (count($list) > 0) {
            $arr = array();
            $data['status'] = 'ok';
            for ($i=0;$i<count($list);$i++) {
                $is_add = true;
                if ($is_add == true) {
                    $voucher['name'] = $list[$i]['name'];
                    $voucher['start_date'] = $list[$i]['start_date'];
                    $voucher['end_date'] = $list[$i]['end_date'];
                    $voucher['money'] = $list[$i]['money'];
                    $voucher['type'] = $list[$i]['type'];
                    $voucher['use_money'] = $list[$i]['use_money'];
                    $voucher['remark'] = $list[$i]['remark'];
                    $voucher['pname'] = '';
                    if (!empty($list[$i]['pname'])) {
                        $voucher['pname'] = $list[$i]['pname'];
                        $voucher['totals'] = $list[$i]['totals']/$list[$i]['ptotals'];
                    } else {
                        $voucher['totals'] = $list[$i]['totals'];
                    }

                    array_push($arr, $voucher);
                }
            }
            $data['list'] = $arr;
        } else {
            $data['status'] = 'no';
        }
        $data['totals'] = $totals;
        $this->ajaxReturn($data);
    }

    public function coupondetails() {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$url = isLogin();
        if ($url != false) {
            header("Location:".$url);
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }
        if (empty(session('user_id'))) {
			session("showLogin", 1);
            $rel_url = "../index";
            redirect($rel_url);
            // $this->display($rel_url);
            exit;
        }

        $this->display();
    }

    public function mygroup(){
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$url = isLogin();
        if ($url != false) {
            header("Location:".$url);
        }
        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }
        if (empty(session('user_id'))) {
			session("showLogin", 1);
            $rel_url = "../index";
            redirect($rel_url);
            // $this->display($rel_url);
            exit;
        }

        $AGENTCONFIG = C('AGENTCONFIG');
        $REBATELAYER = C('TMPL_PARSE_STRING.__REBATELAYER__');
        $REBATELAYERALIAS = C('TMPL_PARSE_STRING.__REBATELAYERALIAS__');

        $data = UserApi::getUserInfo(session("user_id"));

        // 根据顶级ID获取团队交易总额
        $sum_order_price = UserApi::getGroupTotalOrderPrice(session("user_id"));
        // 根据团队交易总额获取返利规则
        $rebate_ratio_list = RebateRatio::getRebateRatioList($sum_order_price);

        $field_list = array();$field_alias_list = array();$join = '';
        for ($i=0; $i<$REBATELAYER; $i++) {
            $alias = ($i+1).'u';
            $alias2 = $i.'u';
            $field_alias = $alias.'ids';
            $join .= " left join fs_user $alias on $alias.pid = $alias2.id";
            $field = "count(distinct $alias.id) as $field_alias"."c";

            $field .= ",GROUP_CONCAT(distinct $alias.id) as $field_alias";

            array_push($field_list, $field);
            array_push($field_alias_list, $field_alias);
        }

        $model = M();
        $all_lower_ids = $model->table('fs_user 0u')
            ->join($join)
            ->field(implode(',',$field_list))
            ->where(array('0u.id' => session('user_id')))
            ->find();

        $rel = array();
        $sy = 0;
        $groupnames = explode(',', $REBATELAYERALIAS);
        if (!empty($rebate_ratio_list)) {
            $rebate_ratio = $rebate_ratio_list[0]['rebate_ratio'];
            $rebate_ratio_arr = explode(",",$rebate_ratio);
            for ($i=0;$i<$REBATELAYER;$i++) {

                for ($j=0;$j<count($rebate_ratio_arr); $j++) {
                    $rebate_ratio_layer = explode("|",$rebate_ratio_arr[$j]);
                    if ($rebate_ratio_layer[0] == ($i+1)) {
                        $real_total_price = OrderApi::getTotalOrderMoney($all_lower_ids[($i+1).'uids']);
                        if ($AGENTCONFIG[$data['agent_level']]['config'][7] == 1) {
                            //$real_total_gain_price = OrderApi::getTotalOrderMoney($all_lower_ids[($i+1).'uids']);
                            $real_total_gain_price = OrderApi::getTotalOrdeGainMoney($all_lower_ids[($i+1).'uids']);
                            $sy += $real_total_gain_price;
                        } else {
                            $sy += $real_total_price*$rebate_ratio_layer[1]/100;
                        }

                        $group['name'] = $groupnames[$i];
                        $group['ratio'] = $rebate_ratio_layer[1]."%";
                        $group['sum_order_price'] = sprintf('%.2f', $real_total_price);
                        $group['get_ratio'] = sprintf('%.2f', $real_total_price*$rebate_ratio_layer[1]/100);
                        array_push($rel, $group);
                    }
                }
            }
        }

        $leval_list = array();
        $py = 0;
        for ($i=0;$i<$REBATELAYER;$i++) {
            $leval["name"] = $groupnames[$i];
            $leval["value"] = $all_lower_ids[($i+1).'uidsc'];
            $py+=$all_lower_ids[($i+1).'uidsc'];
            array_push($leval_list, $leval);
        }

        $this->assign('py', $py);
        $this->assign('sy', sprintf('%.2f', $sy));

        if ($AGENTCONFIG[$data['agent_level']]['config'][7] == 1) {
            $this->assign('leval_list', $leval_list);
            $this->assign('rebate_ratio_list', $rel);
            $this->display("mygroup2");
        } else {
            $this->display();
        }
    }

    public function getnextuser($page=0, $pagesize=10) {
		$url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
		$arr['url'] = isLogin();
        if ($arr['url'] != false) {
            $this->ajaxReturn($arr);
            exit;
        }
        $data = UserApi::getGroupUserList(session('user_id'), $pagesize, $page);
        $date['list'] = $data['data']['list'];
        $date['total'] = $data['data']['total'];
        $date['status'] = 'ok';
        $this->ajaxReturn($date);
    }

    // 二维码
    public function q(){
        $modelObj = M('User');
        $data = $modelObj->field("type, code")->where(array('id' => session("user_id")))->find();
        $code = $data["code"];

        $domain_url = C('TMPL_PARSE_STRING.__DOMAINURL__');
        $web_site_dir = C('TMPL_PARSE_STRING.__WEBSITEDIR__');

        $modelObj = M('Sys');
        $data = $modelObj->field("qrcode_url,qrcode_size,back_x,back_y")->where(array('id' => 1))->find();
        $url = $data['qrcode_url'].$code;//str_replace("{#code}",$code,$data['qrcode_url']);

        $rootPath = C('TMPL_PARSE_STRING.__UPLOAD__');
        $qRcode_path = C('TMPL_PARSE_STRING.__QRCODEBGPATH__');
        $aRcode_name = C('TMPL_PARSE_STRING.__QRCODEBGNAME__');

        $logo = $rootPath.$qRcode_path."/".$aRcode_name.".jpg";//已经生成的原始二维码图
        $QR = $rootPath.$qRcode_path."/u".session("user_id")."_QRCode.png";//已经生成的原始二维码图

        qrcode($url,$data['qrcode_size'], $QR);

        $bg_image_c = imagecreatefromstring(file_get_contents($logo));
        $sub_image_c = imagecreatefromstring(file_get_contents($QR));

        imagecopyresampled($bg_image_c, $sub_image_c, $data['back_x'], $data['back_y'], 0, 0, imagesx($sub_image_c), imagesy($sub_image_c), imagesx($sub_image_c), imagesy($sub_image_c));
        imagejpeg($bg_image_c, $QR, 80);
        imagedestroy($sub_image_c);
        imagedestroy($bg_image_c);

        $date['status'] = 'ok';
        $date['data'] = $domain_url.$web_site_dir.$QR;
        $this->ajaxReturn($date);



        /*$image_1 = imagecreatefromjpeg($logo);
        $image_2 = imagecreatefrompng($QR);
        //创建一个和人物图片一样大小的真彩色画布（ps：只有这样才能保证后面copy装备图片的时候不会失真）
        $image_3 = imageCreatetruecolor(imagesx($image_1), imagesy($image_1));
        //为真彩色画布创建白色背景，再设置为透明
        // $color = imagecolorallocate($image_3, 255, 255, 255);
        $color = imagecolorallocate($image_3, 0, 0, 255);
        imagefill($image_3, 0, 0, $color);
        imageColorTransparent($image_3, $color);
        //首先将人物画布采样copy到真彩色画布中，不会失真
        imagecopyresampled($image_3, $image_1, 0, 0, 0, 0, imagesx($image_1), imagesy($image_1), imagesx($image_1), imagesy($image_1));
        //再将装备图片copy到已经具有人物图像的真彩色画布中，同样也不会失真
        imagecopymerge($image_3, $image_2, $data['back_x'], $data['back_y'], 0, 0, imagesx($image_2), imagesy($image_2), 99);

        copy($image_3, 'Uploads/QRCode/'.$image_3);
        imagecreatefrompng($image_3);

        //将画布保存到指定的gif文件
        imagepng($image_3);*/

        // qrcode($url,9);
    }

	public function suggest() {
        $url = userState();
        if ($url != false) {
            $this->success('',$url);
        }
        $url = isLogin();
        if ($url != false) {
            header("Location:".$url);
        }

        $MAINTAIN = C('__MAINTAIN__');
        if ($MAINTAIN == true) {
            session("user_id", null);
            session("mobile_phone", null);
            session("organization_code", null);
            exit("系统维护中");
        }

        if (empty(session('user_id'))) {
            session("showLogin", 1);
            $rel_url = "../index";
            redirect($rel_url);
            // $this->display($rel_url);
            exit;
        }

        $modelObj = M("user");
        $data = $modelObj->field("REPLACE(mobile_phone, SUBSTR(mobile_phone,4,4), '****') as mobile_phone, balance, photo_url, nick_name")->where(array('id' => session('user_id')))->find();
        $this->assign('user', $data);

        $modelObj = M("UserBank");
        $userBank_list = $modelObj->where(array('user_id'=>session('user_id')))->select();
        $userBank = array();
        if (!empty($userBank_list)) {
            $userBank = $userBank_list[0];
        }
        $this->assign('userBank', $userBank);

        $this->assign('source', 1);

        $modelObj = M("Sys");
        $data = $modelObj->field("lowest_money, highest_money, max_extract_count")->where(array('id' => 1))->find();
        $this->assign('sys', $data);

        $this->display();
    }
	
	
}